package com.tbb.app.base.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.tbb.app.base.search.MessagePageSearch;
import com.tbb.app.base.service.IMessageService;
import com.tbb.app.base.service.IUserService;
import com.tbb.app.base.vo.MessageVO;
import com.tbb.app.base.vo.UserVO;
import com.tbb.app.common.entity.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/zyx")
@Slf4j
@ApiSupport(order = 6)
@Api(tags = "张雨曦相关接口")
//@CrossOrigin(origins = "*")
public class ZYXController {

    @Autowired
    private IUserService iUserService;
    @Autowired
    private IMessageService iMessageService;

    @GetMapping("/user/follow/list")
    @ApiOperation(value = "查询已关注用户列表")
    @ApiOperationSupport(order = 1)
    public BaseResponse<List<UserVO>> listFollow() {
        return BaseResponse.data(iUserService.listFollow());
    }

    @GetMapping("/user/detail")
    @ApiOperation(value = "查询用户详情")
    @ApiOperationSupport(order = 2)
    public BaseResponse<UserVO> detailUser(
            @RequestParam(required = false)
            @ApiParam(value = "用户id，不填则表示本人")
                    String userId) {
        return BaseResponse.data(iUserService.detail(userId));
    }

    @PostMapping("/message/page")
    @ApiOperation(value = "分页查询好友历史消息，时间降序排列")
    @ApiOperationSupport(order = 3)
    public BaseResponse<IPage<MessageVO>> pageMessage(
            @RequestBody
            @Validated
                    MessagePageSearch search) {
        return BaseResponse.data(iMessageService.page(search));
    }

}
